package edu.com.javeriana.aes.gestion.fundacion.ejb;

import edu.com.javeriana.aes.gestion.fundacion.entity.Materia;
import java.util.Collection;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 *
 * @author gersua
 */
@Stateless
public class AdministrarMaterias implements AdministrarMateriasLocal {

    @PersistenceContext(unitName = "FundacionDEL-ejbPU")
    private EntityManager entityManager;

    public void crearMateria(Materia materia) {
        entityManager.persist(materia);
    }

    public Materia buscarMateria(String nombreMateria) {
        Query query = entityManager.createNamedQuery("Materia.findByNombre");
        return (Materia) query.getSingleResult();
    }

    public Collection<Materia> consultarMaterias() {
        Query query = entityManager.createNamedQuery("Materia.findAll");
        return query.getResultList();
    }

    public void ediatarMateria(Materia materia) {
        entityManager.merge(materia);
    }

    public void eliminarMateria(Materia materia) {
        entityManager.remove(materia);
    }
}
